package gui.Teacher;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

import control.BlockFormControl;

import BaseClasses.isRestricted;
import System.MainControl;
import System.SystemObject;
import java.awt.SystemColor;

/**
 * this class is used to Block or unblock a parent from getting in the dataBase
 */
public class BlockForm extends JPanel implements ActionListener
{
	/**StudentID text field*/
	private JTextField textstudentID;
	/**ParentID label*/
	private JLabel lblexamId;
	/**Unblock/Block button*/
	private JButton btnUnblock;
	/**cancel button*/
	private JButton btnCancel;
	/**control class*/
	private BlockFormControl control = new BlockFormControl();

	/**
	 * Create the panel.
	 */
	public BlockForm()
	{
		super();
		initialize();
	}
	
	/**
	 * initialize the panel.
	 */
	public void initialize()
	{
		setBorder(new TitledBorder(null, "Exam Block / Unblock", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		setBackground(SystemColor.activeCaption);
		setBounds(MainControl.guiX,MainControl.guiY,500,400);
		setLayout(null);
		MainControl.frame.setBounds(this.getBounds());
	   
		add(getlblExamId());
		add(gettextstudentID());
		
		//add buttons
		add(getbtnUnblock());
		add(getbtnCancel());
	
	}
	/**
	 * @ Override
	 */
	public void actionPerformed(ActionEvent e) 
	{
		isRestricted studentUI = new isRestricted();
		SystemObject obj = new SystemObject();
		if (e.getSource() == btnCancel)//if cancel is pressed 
		{
			MainControl.setGUI(MainControl.currentUser.getRole(), this);//return to principal main window
		}
		if (e.getSource() == btnUnblock)//if show Block/Unblock is pressed
		{
			studentUI.setUsrId(textstudentID.getText());
			/**Change parent status of blocking from entering the system
			 * if parent was unblocked we change his status to blocked,and contrary
			 */
			obj = control.changBlock(studentUI);
			/**
			 * show the principal the new status of the parent or if their was a problem
			 */
			JOptionPane.showMessageDialog(null,(String)obj.getObj(),"Result Window",JOptionPane.INFORMATION_MESSAGE);		
			MainControl.setGUI(MainControl.currentUser.getRole(), this);//return to principal main window
		}
	
	}
	/**
	 * Creates StudentId label
	 *@return new JLabel
	 */
	public JLabel getlblExamId()
	{
		if(null == lblexamId)
		{
			lblexamId = new JLabel("Student ID");
			lblexamId.setFont(new Font("Microsoft New Tai Lue", Font.BOLD, 13));
			lblexamId.setBounds(42, 90, 90, 14);
		}
		return lblexamId;
	}
	/**
	 * Creates block/unblock button
	 *@return new JButton
	 */
	public JButton getbtnUnblock()
	{
		if(null == btnUnblock)
		{
			btnUnblock = new JButton("UNBLOCK/BLOCK");
			btnUnblock.setBorder(BorderFactory.createLineBorder(new Color(0, 0, 205)));
			btnUnblock.setFont(MainControl.guiFont);
			btnUnblock.setForeground(new Color(0, 0, 205));
			btnUnblock.setSize(new Dimension(180,30));
			btnUnblock.setLocation(50, 227);
			btnUnblock.addActionListener(this);
		}
		return btnUnblock;
	}
	/**
	 * Creates field text for "textstudentID"
	 *@return new JTextField
	 */
	public JTextField gettextstudentID()
	{
		if(null == textstudentID)
		{
			textstudentID = new JTextField();
			textstudentID.setBounds(167, 87, 118, 20);
			textstudentID.setColumns(10);
		}
		return textstudentID;
	}
	
	/**
	 * Creates cancel button
	 *@return new JButton
	 */
	public JButton getbtnCancel()
	{
		if(null == btnCancel)
		{
			btnCancel = new JButton("cancel");
		    btnCancel.setBorder(BorderFactory.createLineBorder(Color.RED));
		    btnCancel.setFont(MainControl.guiFont);
			btnCancel.setForeground(Color.RED);
			btnCancel.setLocation(254, 227);
			btnCancel.setSize(MainControl.btnsDimesion);
			btnCancel.addActionListener(this);
		}
		return btnCancel;
	}
	

}
